﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CommandBinding.cs" company="">
//   
// </copyright>
// <summary>
//   The command binding.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Bindings
{
    using Libium.UseCases;
    using Libium.Views;

    /// <summary>
    ///   The command binding.
    /// </summary>
    public class CommandBinding : BindableViewBinding<ICommand, ICommandView>
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandBinding"/> class.
        /// </summary>
        /// <param name="service">
        /// The service. 
        /// </param>
        /// <param name="command">
        /// The command. 
        /// </param>
        /// <param name="view">
        /// The view. 
        /// </param>
        public CommandBinding(IBindService service, ICommand command, ICommandView view)
            : base(service, command, view)
        {
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///   The bind.
        /// </summary>
        public override void Bind()
        {
            base.Bind();
            View.Text = UseCase.Text;
            View.Tooltip = UseCase.Description;
            View.Execute += OnViewExecute;
        }

        /// <summary>
        ///   The unbind.
        /// </summary>
        public override void Unbind()
        {
            base.Unbind();
            View.Execute -= OnViewExecute;
        }

        #endregion

        #region Methods

        /// <summary>
        /// The on view execute.
        /// </summary>
        /// <param name="view">
        /// The view. 
        /// </param>
        private void OnViewExecute(ICommandView view)
        {
            UseCase.Execute();
        }

        #endregion
    }
}